﻿using MvcApplication1.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcApplication1.Models
{
    public class DailyUpdatesModel
    {
        public List<StorageService.Report> reports = new List<StorageService.Report>();

        public DailyUpdatesModel()
        {
            
        }

        /// <summary>
        /// Parses a VIN into the corresponding driver name.
        /// </summary>
        /// <param name="report">Report containing the appropriate VIN.</param>
        /// <returns>String containing the name of the driver associated with the VIN.</returns>
        public string ParseVIN(StorageService.Report report, string username)
        {
            string VIN = report.VIN;
            string line = "";
            string name = "";
            string filePath = HttpContext.Current.Server.MapPath("~/Data/drivernames.txt");
            using (StreamReader reader = new StreamReader(filePath))
            {
                do
                {
                    line = reader.ReadLine();
                } while (line != username && !reader.EndOfStream);

                while (!reader.EndOfStream)
                {
                    line = reader.ReadLine();
                    name = reader.ReadLine();
                    if (line == VIN)
                    {
                        return name;
                    }
                }
            }
            return "Driver Name Not Available";
        }
    }
}